home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1853 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Destructors in functions
  5. Date: Sat, 13 Jan 1996 13:52:10 GMT
  6. Organization: Netcom
  7. Message-ID: <30f7b83b.67708480@nntp.ix.netcom.com>
  8. References: <4d7r65$dv9@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: ix-dc11-30.ix.netcom.com
  10. X-NETCOM-Date: Sat Jan 13  5:51:54 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. weatby@aol.com (Weatby) wrote:
  14.  
  15. |>If you pass an object to a function, the language makes a bitwise
  16. copy of
  17. |>it, local to the function.  (Assuming no copy constructor is
  18. defined.) 
  19. |>Then, on the way out, the function calls the user-defined
  20. constructor.
  21. |>
  22. |>This will cause problems if the object has any pointers in it (if
  23. they are
  24. |>released by the destructor, as they 'should' be).
  25. |>
  26. |>The question is, why call a destructor on an object for which no
  27. |>constructor was called?  The compiler has probably put the local
  28. copy on
  29. |>its stack, and could pop it off on the way out.
  30. |>
  31. |>Calling a destructor, automatically, for which no constructor was
  32. called
  33. |>seems to be a non-useful feature.  Does anyone know why this was
  34. included
  35. |>in the language definition?
  36.  
  37. First, if a bitwise copy is really being done, get a new compiler.  It
  38. should do a memberwise copy.  The difference is that any members that
  39. have copy constructors should be copied using those.
  40.  
  41. Second, a constructor is being called.  The default copy constructor
  42. does a memberwise copy.  If the default copy constructor does not do
  43. what you want, you need to write your own.
  44.  
  45.  
  46. Michael M Rubenstein
  47.